<template>
	<view class="">
		<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :back-top="true">
			<view class="column" style="padding-top: 20rpx;">
				<view class="item-con row between" v-for="(item, index) in dataList" :key="index" @tap="checkedItem(item, index)" :class="{ active: index == currentIndex }">
					<view class="item-l" style="width: 80%;">
						<view class="item-l-i">
							<text>团长:{{ item.name }}</text>
							<text style="margin-left: 40rpx;">{{ item.phone }}</text>
						</view>
						<view class="clamp item-l-d">{{ item.addressDetail }}</view>
					</view>
					<view class="item-r">{{ item.distance }}km</view>
				</view>
			</view>
		</s-pull-scroll>
		<mix-loading v-if="isLoading"></mix-loading>
	</view>
</template>

<script>
export default {
	data() {
		return {
			currentIndex: 0,
			dataList: []
		};
	},
	onLoad() {
		this.refresh();
	},
	methods: {
		async checkedItem(v, k) {
			const data = {
				uid: uni.getStorageSync('uid'),
				tzId: v.id
			};
			const res = await this.$request('user/band-tz', data);
			if (res.result == 0) {
				this.currentIndex = k;
				this.$util.prePage().leader=v;
				this.back();
			} else {
				this.$util.msg(res.resultNote);
			}
		},
		pullDown(pullScroll) {
			setTimeout(() => {
				this.loadData(pullScroll);
			}, 200);
		},
		async loadData(pullScroll) {
			const data = {
				uid: uni.getStorageSync('uid'),
				lng: uni.getStorageSync('point').lng,
				lat: uni.getStorageSync('point').lat,
				pageNo: pullScroll.page,
				pageSize: '10'
			};
			const res = await this.$request('user/tz-list', data, { showLoading: true });
			if (pullScroll.page == 1) this.dataList = [];
			if (res.result == 0) {
				this.dataList = this.dataList.concat(res.data.list);
				pullScroll.endByPage(Math.ceil(res.data.count / 10), res.data.list);
			} else {
				this.$util.msg(res.resultNote);
			}
		}
	}
};
</script>

<style scoped lang="scss">
.active {
	border: 1px solid rgba(39, 129, 167, 1) !important;
}
.item-con {
	margin-bottom: 20rpx;
	width: 706upx;
	height: 140upx;
	border-radius: 20upx;
	border: 1px solid rgba(39, 129, 167, 0.2);
	padding: 20upx;
}
.item-r {
	font-size: 26upx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #2781a7;
}
.item-l {
	border-right: 1px solid #e7e7e7;
}
.item-l-i {
	text {
		font-size: 28upx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 42upx;
	}
}
.item-l-d {
	font-size: 24upx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;
	line-height: 42upx;
}
</style>
